<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>智能模块 - 显示内容</title>
    <link type="text/css" rel="stylesheet" th:href="@{${skinPath} + '/css.css'}"/>
    <link rel="stylesheet" href="../js/bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="../js/layui/css/layui.css" media="all">
    <link href="../lte/css/font-awesome.min.css?v=4.4.0" rel="stylesheet"/>
    <style type="text/css">
        #attDiv {
            margin-top: 10px;
        }

        #loading {
            position: fixed;
            z-index: 400;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            text-align: center;
            font-size: 0.9rem;
            color: #595758;
            background-color: #ffffff;
            /*
            filter: alpha(Opacity=60);
            -moz-opacity: 0.6;
            opacity: 0.6;
            */
        }

        [(${pageCss})]
    </style>
    <script src="../inc/common.js"></script>
    <script src="../inc/map.js"></script>
    <script src="../js/jquery-1.9.1.min.js"></script>
    <script src="../js/jquery-migrate-1.2.1.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../js/MyPaging/MyPaging.css">
    <script src="../js/MyPaging/MyPaging.js"></script>
    <script src="../js/jquery.raty.min.js"></script>
    <script src="../js/jquery-alerts/jquery.alerts.js" type="text/javascript"></script>
    <script src="../js/jquery-alerts/cws.alerts.js" type="text/javascript"></script>
    <link href="../js/jquery-alerts/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen"/>
    <script src="../inc/flow_dispose_js.jsp"></script>
    <script src="../inc/flow_js.jsp"></script>
    <script th:src="@{'/flow/form_js/form_js_' + ${formCode} + '.jsp?pageType=show&id=' + ${id} + '&moduleCode=' + ${code} + '&random=' + ${random}}"></script>
    <script src="../inc/ajax_getpage.jsp"></script>

    <link href="../js/select2/select2.css" rel="stylesheet"/>
    <script src="../js/select2/select2.js"></script>
    <script src="../js/select2/i18n/zh-CN.js"></script>
    <script src="../js/BootstrapMenu.min.js"></script>
    <link href="../js/jquery-showLoading/showLoading.css" rel="stylesheet" media="screen" />
    <script type="text/javascript" src="../js/jquery-showLoading/jquery.showLoading.js"></script>
</head>
<body>
<div id="loading">
    <img src="../images/loading.gif" alt="loading.." style="margin-top:50px;"/>
</div>
<div th:if="${hasTab}" class="tabs1Box">
    <div id="tabs1">
        <ul>
            <li th:each="json : ${aryTab}" th:id="${json.id}" th:attr="tagName=${json.name}">
                <th:block th:switch="${json.get('target')!=null and json.target eq 'newTab'}">
                    <th:block th:case="true">
                        <a href="javascript:;" th:title="${json.name}" th:onclick="addTab('[(${json.name})]', '[(${json.url})]')"><span>[(${json.name})]</span></a>
                    </th:block>
                    <th:block th:case="*">
                        <a th:href="${json.url}" th:title="${json.name}"><span>[(${json.name})]</span></a>
                    </th:block>
                </th:block>
            </li>
        </ul>
    </div>
    <script>
        $('#menu1').addClass('current');
    </script>
</div>
<div class="spacerH"></div>
<div id="visualDiv">
    <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td align="center">
                <form name="visualForm" id="visualForm">
                    [(${rend})]
                </form>
            </td>
        </tr>
        <tr>
            <td align="center"></td>
        </tr>
        <tr th:if="${isHasAttachment}">
            <td align="left">
                <div id="attDiv">
                </div>
            </td>
        </tr>
        <tr>
            <td height="30" align="center" style="padding: 10px 0">
                <input name="id" th:value="${id}" type="hidden"/>
                <th:block th:if="${#lists.size(buttons)==0}">
                    <button class="btn btn-default" onclick="showFormReport()">打印</button>
                    <!--
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <input class="btn" type="button" onclick="exportToWord()" value="导出Word"/>
                    -->
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <button th:if="${btn_edit_display}" class="btn btn-default" th:onclick="edit()">编辑</button>
                </th:block>
                <th:block th:each="button : ${buttons}">
                    <th:block th:switch="${button.event}">
                        <button th:case="click" th:id="${button.id}" class="btn btn-default" th:title="${button.title}" th:onclick="[(${button.href})]">[(${button.name})]</button>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <button th:case="newTab" th:id="${button.id}" class="btn btn-default" th:title="${button.title}" th:onclick="addTab('[(${button.name})]', '[(${button.href})]')">[(${button.name})]</button>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <button th:case="curTab" th:id="${button.id}" class="btn btn-default" th:title="${button.title}" th:onclick="window.location.href='[(${button.href})]'">[(${button.name})]</button>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                    </th:block>
                </th:block>
            </td>
        </tr>
    </table>
</div>
<form id="formWord" name="formWord" target="_blank" action="module_show_word.jsp" method="post">
    <textarea name="cont" style="display:none"></textarea>
</form>
<script src="../js/layui/layui.js" charset="utf-8"></script>
<script th:inline="javascript">
    var isPageStyleLight = [(${isPageStyleLight})]
    if (isPageStyleLight) {
        // 不能放在$(function中，原来的tabStyle_8风格会闪现
        // $(function() {
        var $table = $('#visualForm').find('.tabStyle_8');
        if ($table[0] == null) {
            $table = $('#visualForm').find('.tabStyle_1');
        }
        $table.addClass('layui-table');
        $table.removeClass('tabStyle_8');
        // })
    }

    function getPrintContent() {
        return "<div style='text-align:center;margin-top:10px'>" + $('#visualDiv').html() + "</div>";
    }

    function showFormReport() {
        window.open('../print_preview.jsp?print=true', '', 'left=0,top=0,width=550,height=400,resizable=1,scrollbars=1, status=1, toolbar=1, menubar=1');
    }

    function exportToWord() {
        o("cont").value = o("formDiv").innerHTML;
        o("formWord").submit();
    }

    // i从1开始
    function getCellValue(i, j) {
        var obj = document.getElementById("cwsNestTable");
        var cel = obj.rows.item(i).cells;

        var fieldType = Main_Tab.rows[0].cells[j].getAttribute("type");
        var macroType = Main_Tab.rows[0].cells[j].getAttribute("macroType");

        // 标值控件
        if (macroType == "macro_raty") {
            if (cel[j].children[0] && cel[j].children[0].tagName == "SPAN") {
                var ch = cel[j].children[0].children;
                for (var k = 0; k < ch.length; k++) {
                    if (ch[k].tagName == "INPUT") {
                        return ch[k].value;
                    }
                }
            }
        }
        // 在clear_color时，会置宏控件所在单元格的value属性为控件的值
        else if (cel[j].getAttribute("value")) {
            return cel[j].getAttribute("value");
        } else {
            if (cel[j].children.length > 0) {
                var cellDiv = cel[j].children[0];
                return cellDiv.innerText.trim();
            } else {
                return cel[j].innerText.trim();
            }
        }
        return "";
    }

    // 前提：所有ajax请求都是用jQuery的$.ajax发起的，而非原生的XHR；
    var ajaxBack = $.ajax;
    var ajaxCount = 0;
    var allAjaxDone = function () {
        // 所有 AJAX 请求已完成
        try {
            // 可在form_js_***.jsp中写此方法
            onAjaxLoaded();
        } catch (e) {
        }
        $("#loading").hide();
    };
    // 由于get/post/getJSON等，最后还是调用到ajax，因此只要改ajax函数即可
    $.ajax = function (setting) {
        ajaxCount++;
        var cb = setting.complete;
        setting.complete = function () {
            if ($.isFunction(cb)) {
                cb.apply(setting.context, arguments);
            }
            ajaxCount--;
            if (ajaxCount == 0 && $.isFunction(allAjaxDone)) {
                allAjaxDone();
            }
        };
        ajaxBack(setting);
    };

    $(function () {
        // 如果没有ajax，则ajaxCount为0，应置loading为hide
        if (ajaxCount == 0) {
            $("#loading").hide();
        }

        loadAttachment();
    })

    var isPageStyleLight = [(${isPageStyleLight})];
    if (isPageStyleLight) {
        // 不能放在$(function中，原来的tabStyle_8风格会闪现
        // $(function() {
        var $table = $('#visualForm').find('.tabStyle_8');
        $table.addClass('layui-table');
        $table.removeClass('tabStyle_8');
        // })
    }

    function loadAttachment() {
        $.ajax({
            type: "post",
            url: "moduleAttListPage.do",
            data: {
                id: "[(${id})]",
                code: "[(${code})]",
                isShowPage: true
            },
            dataType: "html",
            beforeSend: function(XMLHttpRequest){
                $('#visualForm').showLoading();
            },
            success: function(data, status){
                $('#attDiv').html(data);
            },
            complete: function(XMLHttpRequest, status){
                $('#visualForm').hideLoading();
            },
            error: function(XMLHttpRequest, textStatus){
                alert(XMLHttpRequest.responseText);
            }
        });
    }

    function edit() {
        window.location.href='moduleEditPage.do?parentId=[(${id})]&id=[(${id})]&isShowNav=[(${isShowNav})]&code=[(${code})]';
    }
</script>
</body>
</html>